The mask
modifier clips the visual rendering of a view using the alpha channel of another view. Only the parts of the original view that align with the opaque (non-transparent) portions of the mask remain visible; the rest is hidden.
This is commonly used to apply custom shapes, spotlight effects, or partial reveals.
Apply a mask view directly. The mask is centered on the base view by default.
In this example, the image is clipped to a circular shape using a Circle
as the mask. Only the circular portion of the image is visible.
Use this form when you want to position the mask relative to the base view.
Alignment
values:"top"
| "bottom"
| "leading"
| "trailing"
"topLeading"
| "topTrailing"
| "bottomLeading"
| "bottomTrailing"
"center"
Only the top half of the blue rectangle will be visible, defined by the opaque rectangle used as the mask.
The mask view’s opacity determines the visibility of the base view.
The mask does not affect layout, only how the content is rendered.
Use frame={{ width, height }}
on both base and mask views to ensure proper alignment and coverage.
Field | Description |
---|---|
mask (VirtualNode) |
A view that defines the clipping mask; centered by default |
alignment |
Optional. Aligns the mask view relative to the base view |
content |
The actual masking content used to clip rendering |